@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.5.2')

import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.json.*

import org.apache.http.client.methods.*
import org.apache.http.entity.*
import org.apache.http.impl.client.*


class GitLabAPI {
    static void main(args) {
       println "Hello World"
//curl --request GET --header "PRIVATE-TOKEN:1qfBxwCzmLRknsuFZQXs" "https://git.devopsing.com.cn/api/v4/projects/3976/members/1696/"
       // build JSON
        def map = [:]
        map["email"] = "Maritime DevCon"
        map["address"] = "Fredericton"
        map["handle"] = "maritimedevcon"

        def jsonBody = new JsonBuilder(map).toString()

         // build HTTP POST
        // def url = 'http://jsonplaceholder.typicode.com/posts'
        def url="https://git.devopsing.com.cn/api/v4/users/1696"
//        def post = new HttpPost(url)


        def get=new HttpGet(url)
//        post.addHeader("content-type", "application/json")
//        post.setEntity(new StringEntity(jsonBody))
          get.addHeader("content-type", "application/json")
          get.setEntity(new StringEntity(jsonBody))

         // execute
        def client = HttpClientBuilder.create().build()
//        def response = client.execute(post)
        def response = client.execute(get)

//        def bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))
//        def jsonResponse = bufferedReader.getText()
//        println "response: \n" + jsonResponse
//
//        def slurper = new JsonSlurper()
//        def resultMap = slurper.parseText(jsonResponse)
//        println(resultMap.toString())

//        assert "Maritime DevCon" == resultMap["name"]
//        assert resultMap["id"] != null

    }
}